package xin.nick.bot.listener;

import catcode.CatCodeUtil;
import love.forte.common.ioc.annotation.Beans;
import love.forte.common.ioc.annotation.Depend;
import love.forte.simbot.annotation.OnGroup;
import love.forte.simbot.annotation.OnPrivate;
import love.forte.simbot.api.message.MessageContentBuilderFactory;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.message.events.PrivateMsg;
import love.forte.simbot.api.sender.MsgSender;


/**
 * @author: Nick inickning@outlook.com
 * @Date: 2021/3/31 20:40
 * @Description:
 */
@Beans
public class TestListener {

    @Depend
    private MessageContentBuilderFactory messageContentBuilderFactory;




    @OnPrivate
    public void privateMsg(PrivateMsg privateMsg, MsgSender sender) {
        System.out.println("收到私信:---");
        System.out.println(privateMsg);
        System.out.println("回复私信:---" + privateMsg.getAccountInfo().getAccountCode());
        String resultMsg = privateMsg.getMsg() + "\n--------\n 假装我是复读机";
        System.out.println(resultMsg);
        sender.SENDER.sendPrivateMsg(privateMsg, resultMsg);
//        CatCodeUtil catCodeUtil = CatCodeUtil.getInstance();
//        catCodeUtil
//        sender.SENDER.sendPrivateMsg(privateMsg, "[CAT:rich,content=<?xml version&#61;'1.0' encoding&#61;'UTF-8' standalone&#61;'yes' ?><msg serviceID&#61;\"108\" templateID&#61;\"1\" action&#61;\"web\" brief&#61;\"&#91;开机&#93;\" sourcePublicUin&#61;\"3192985373\" sourceMsgId&#61;\"0\" url&#61;\"https://youxi.vip.qq.com/m/act\" flag&#61;\"0\" adverSign&#61;\"0\" multiMsgFlag&#61;\"0\"><item layout&#61;\"2\" advertiser_id&#61;\"0\" aid&#61;\"0\"><picture cover&#61;\"http://gchat.qpic.cn/gchatpic_new/2292380798/676360846-3001560960-747D42C6EDE56D655BCC8E34E187464C/0?term&#61;2\" w&#61;\"0\" h&#61;\"0\" /><title>开机成功</title><summary></summary></item><source name&#61;\"\" icon&#61;\"\" action&#61;\"web\" appid&#61;\"-1\" /></msg>]");


    }

    @OnGroup
    public void myGroup(GroupMsg groupMsg, MsgSender sender) {
        System.out.println("收到群聊:---");
        System.out.println(groupMsg);
        String myGroupNumber = "492781269";
        String currentGroupNumber = groupMsg.getGroupInfo().getGroupCode();
        if(myGroupNumber.equals(currentGroupNumber)) {
            String currentMsg = groupMsg.getMsg();
            System.out.println(groupMsg.getFlag());
            if(currentMsg.contains("?") ||currentMsg.contains("吗") || currentMsg.contains("？")) {

                System.out.println(currentMsg);



//                String resultMsg = currentMsg;
//                resultMsg = resultMsg.replace("吗","");
//                resultMsg = resultMsg.replace("?","!");
//                resultMsg = resultMsg.replace("？","!");
//                System.out.println("回复群聊:---" + myGroupNumber + ":" + groupMsg.getGroupInfo().getGroupName());
//                System.out.println(resultMsg);
//                sender.SENDER.sendGroupMsg(groupMsg, resultMsg);
            }

        }


    }

}
